<template>
	<view class="controlCenter">
		<uni-section title="对开售票开关" type="line">
			<view class="text">
				关闭后，本场次鱼票对钓友和票务停售
			</view>
			<switch class="switch" :checked="data.is_coupon_card" color="#D43030"  style="transform:scale(0.7)" @change="switch1Change"/>
		</uni-section>
		<uni-section title="优惠券开关" type="line">
			<view class="text">
				关闭后，本场次鱼票不能使用优惠券
			</view>
			<switch class="switch" :checked="data.is_ticket_sales" color="#D43030"  style="transform:scale(0.7)" @change="switch2Change"/>
		</uni-section>
		<uni-section title="修改鱼讯" type="line" @click="goto('/pages/fishTickets/addSession/editSession')">
			<view class="text">
				可对本场次的票价、时间、人数进行修改
			</view>
			<uni-icons type="right" size="20"></uni-icons>
		</uni-section>
		<uni-section :title="data.is_cancel?'本场次已取消':'取消本场次'" type="line"  @click="dialogToggle">
			<view class="text" v-show="!data.is_cancel">
				可一键直接取消本场次
			</view>
			<uni-icons type="right" size="20" v-show="!data.is_cancel"></uni-icons>
		</uni-section>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="取消" confirmText="确认" title="您正在取消本场次,请确认!" @confirm="dialogConfirm"
			></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import { control_center, put_control_center } from '@/utils/fishNew/index.js'
	export default {
		data() {
			return {
				data: {
					is_coupon_card: false,
					is_cancel: false,
					is_ticket_sales: false,
					fish_news: null,
					id: null
				},
				Fishnewsid: null
			}
		},
		onLoad(query) {
			this.Fishnewsid = query.id
			this.getDate()
		},
		methods: {
			getDate() {
				control_center({Fishnewsid:this.Fishnewsid}).then(res=>{
					this.data = res.data
				})
			},
			switch1Change(e) {
				let id = this.data.id
				put_control_center({is_coupon_card: e.detail.value},id).then(res=>{
					if(res.code == 200){
						uni.showLoading({
							title: '修改成功！'
						})
						setTimeout(() => {
							uni.hideLoading()
							this.getDate()
						}, 500)
					}
				})
			},
			switch2Change(e) {
				let id = this.data.id
				put_control_center({is_ticket_sales: e.detail.value},id).then(res=>{
					if(res.code == 200){
						uni.showLoading({
							title: '修改成功！'
						})
						setTimeout(() => {
							uni.hideLoading()
							this.getDate()
						}, 500)
					}
				})
			},
			dialogToggle(type) {
				if(!this.data.is_cancel){
					this.$refs.alertDialog.open()
				}
			},
			dialogConfirm() {
				let id = this.data.id
				put_control_center({is_cancel: true},id).then(res=>{
					if(res.code == 200){
						uni.showLoading({
							title: '已取消本场次！'
						})
						setTimeout(() => {
							uni.hideLoading()
							this.getDate()
						}, 800)
					}
				})
			},
			goto(url){
				uni.navigateTo({url:url+"?id="+this.Fishnewsid})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.controlCenter {
		background-color: #F3F4F6;
		padding: 40rpx;
		height: calc(100vh - 44px - env(safe-area-inset-top) - 80rpx);
		.uni-section{
			margin-bottom: 40rpx;
			padding: 0 20rpx 20rpx;
			:deep(.uni-section-content){
				position: relative;
				.text{
					font-size: 24rpx;
					color: rgba(0, 0, 0, 0.8);
				}
				.switch{
					position: absolute;
					right: 0rpx;
					top: -45rpx;
				}
				.uni-icons{
					position: absolute;
					right: 0rpx;
					top: -34rpx;
				}
			}
		}
		:deep(.uni-popup-dialog){
			.uni-dialog-title{
				.uni-popup__info{
					padding-top: 20rpx;
					span{
						font-size: 28rpx !important;
						color: #000000 !important;
					}
				}
			}
			.uni-dialog-content{
				padding: 30rpx;
			}
			.uni-dialog-button-group{
				justify-content: space-around;
				padding-bottom: 30rpx;

				.uni-dialog-button{
					.uni-dialog-button-text{
						height: 60rpx;
						line-height: 60rpx;
						padding: 0 20rpx;
						text-align: center;
						background: #E5E5E5;
						color: #333;
					}
					.uni-button-color{
						color: #fff;
						background: #D43030;
					}
				}
			}
		}
	}
</style>
